코드
import openai
import os
from dotenv import load_dotenv, find_dotenv
= load_dotenv(find_dotenv())
_
= os.getenv('ENV_OPENAI_API_KEY') openai.api_key
In [2]:
In [3]:
import pandas as pd
from pandasai import PandasAI
# Sample DataFrame
df = pd.DataFrame({
"country": ["United States", "United Kingdom", "France", "Germany", "Italy", "Spain", "Canada", "Australia", "Japan", "China"],
"gdp": [21400000, 2940000, 2830000, 3870000, 2160000, 1350000, 1780000, 1320000, 516000, 14000000],
"happiness_index": [7.3, 7.2, 6.5, 7.0, 6.0, 6.3, 7.3, 7.3, 5.9, 5.0]
})
df
country | gdp | happiness_index | |
---|---|---|---|
0 | United States | 21400000 | 7.3 |
1 | United Kingdom | 2940000 | 7.2 |
2 | France | 2830000 | 6.5 |
3 | Germany | 3870000 | 7.0 |
4 | Italy | 2160000 | 6.0 |
5 | Spain | 1350000 | 6.3 |
6 | Canada | 1780000 | 7.3 |
7 | Australia | 1320000 | 7.3 |
8 | Japan | 516000 | 5.9 |
9 | China | 14000000 | 5.0 |
In [4]:
'According to the data, the top 5 happiest countries are the United States, Canada, Australia, United Kingdom, and Germany.'
In [5]:
'Sure, I can help you with that! To create a horizontal bar chart of countries showing their GDP, we can use different colors for each bar. Would you like me to guide you through the process?'